﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunnyFunction
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a1 = new int[] { 1,2,3,0,0,0};
            int[] a2 = new int[] { 2, 5, 6 };

            LeetCode.Merge(a1,3, a2,3);
            //var result = LeetCode.IsMatch("mississipi", "mis*is*p.");
            zChangeTest();
            //TransRome();

            //GuessFlower gf = new GuessFlower(4, 8);
            //gf.Show();


            //var sl = new SaoLei(30, 30);
            //sl.Print();

            //ECBTest.Test();
            //Poker_FiveNiu.Start(5);
            //TestSD();
            //TestPy();
            //PushBox();
            //HD1.Run();
            //FE1.Run();
            //BQBJ.Run();
            //XL.Run();
            //GuessTest();
            //GusNum.Start();
            //CyCleDelete.Run();
            //MyEvent.Test();
            //int[] arr = new int[] { 5, 19, 23, 59, 18, 47, 92, 10, 57, 23 };
            //Console.WriteLine("Be: " + string.Join(",", arr));
            //Sort.BubbleSort(arr);
            //arr= Sort.InsertSort(arr);
            //List<int> l = arr.ToList();
            //List<int> r = Sort.SelectSort(l);
            //arr = r.ToArray();
            //Sort.ShellSort(arr);
            //Sort.HeapSort(arr);
            //arr= Sort.MergeSort(arr);
            //Console.WriteLine("Af: " + string.Join(",", arr));
            //BigNumTest();
            //Poker_JFirst.Play();
            //TestMj2();

            //Console.WriteLine("End");
            Console.ReadLine();
        }

        static void zChangeTest()
        {
            /*
             * A     G    M
             * B   F H   L
             * C E   I K
             * D     J
             * 
             */

            var re = ZChange.Convert("A", 1);
        }

        public static void SortColors(int[] nums)
        {
            int min = 0;
            int max = nums.Length - 1;
            for (int i = 0; i < nums.Length; i++)
            {
                if (nums[i] == 0)
                {
                    Swap(nums, i, min);
                    i--;
                    min++;
                }
                else if (nums[i] == 2 && i<max)
                {
                    Swap(nums, i, max);
                    i--;
                    max--;
                }
            }
        }

        private static void Swap(int[] nums, int x, int y)
        {
            var temp = nums[x];
            nums[x] = nums[y];
            nums[y] = temp;
        }

        static void TransRome()
        {
            while (true)
            {
                Console.WriteLine("输入要转换的数字，0退出！");
                var str = Console.ReadLine();

                if (!int.TryParse(str, out int num))
                {
                    Console.WriteLine("未知的数字！");
                    continue;
                }
                if (num == 0)
                    break;

                var r = RomeNumber.N2R(num);
                Console.WriteLine("转换结果：" + r);
            }
        }

        static void TestPy()
        {
            List<string> list = new List<string>() 
            {
                "曾华苗","王喜雀",
            };

            foreach (var str in list)
            {
                var py = FullPY.GetPinYin(str);

                Console.WriteLine($"{str.PadRight(6, ' ')} => {py}");
            }
        }

        static void TestSD()
        {
            /*
            var str = @"
4 0 0 0 0 0 0 9 3
3 2 9 0 0 0 5 0 8
6 0 8 0 5 9 0 0 0
0 0 0 0 7 4 1 0 0
8 0 0 0 1 0 0 0 2
0 0 7 8 3 0 0 0 0
0 0 0 6 2 0 9 0 1
2 0 1 0 0 0 6 3 7
7 4 0 0 0 0 0 0 5";
            */
            var str = @"
8 0 0 0 0 0 0 0 0
0 0 3 6 0 0 0 0 0
0 7 0 0 9 0 2 0 0
0 5 0 0 0 7 0 0 0
0 0 0 0 4 5 7 0 0
0 0 0 1 0 0 0 3 0
0 0 1 0 0 0 0 6 8
0 0 8 5 0 0 0 1 0
0 9 0 0 0 0 4 0 0";

            var sd = new sudokuForm.Sudoku();
            sd.Init(str);

            var re = sd.GetResult();

            if (re)
            {
                Console.WriteLine("Answer:");
                for (int j = 0; j < 9; j++)
                {
                    for (int i = 0; i < 9; i++)
                    {
                        if (i == 3 || i == 6)
                            Console.Write("|");
                        Console.Write(sd.Map[i, j] + " ");
                    }
                    Console.WriteLine("");
                    if (j == 2 || j == 5)
                    {
                        Console.WriteLine("--------------------");
                    }
                }
            }
        }

        static void PushBox()
        {
            var pb = new PushBox();
            pb.Init();
        }

        static void GuessTest()
        {
            List<int> list = new List<int>();
            for (int i = 0; i < 10; i++)
            {
                list.Add(GuessNum.Start());
                Console.WriteLine("-------");
            }
            var gp = list.GroupBy(t => t).OrderBy(t => t.Key);

            foreach (var g in gp)
            {
                Console.WriteLine($"{g.Key} 次 => {g.Count()}");
            }

            var avg = (double)list.Sum() / list.Count;
            Console.WriteLine("平均 => " + avg);
        }

        static void TestMj2()
        {
            List<mj> mjs = new List<mj>()
            {
                new mj(11),
                new mj(11),
                new mj(11),
                new mj(12),
                new mj(13),
                new mj(14),
                new mj(15),
                new mj(16),
                new mj(17),
                new mj(18),
                new mj(19),
                new mj(19),
                new mj(19),
            };

            var huList = MaJiang.GetHuList(mjs);

            Console.WriteLine(string.Join("", mjs));
            Console.WriteLine("胡牌列表=>");
            Console.WriteLine(string.Join(" | ", string.Join("", huList.Select(t => t.ToString()))));

        }

        static void TestMj()
        {
            List<mj> mjs = new List<mj>()
            {
                new mj(91),
                new mj(91),
                new mj(11),
                new mj(11),
                new mj(11),
                new mj(11),
                new mj(12),
                new mj(14),
                new mj(21),
                new mj(22),
                new mj(22),
                new mj(23),
                new mj(23),
                new mj(24),
            };

            var hu = MaJiang.IsHu(mjs);

            Console.WriteLine(string.Join("", mjs));
            Console.WriteLine("HU => " + hu);
            if (hu)
            {
                Console.WriteLine(string.Join(" | ", MaJiang.BaseList.Select(t => string.Join("", t))));
            }
        }

        static void BigNumTest()
        {
            string num1 = "995.12";
            string num2 = "11111001.22";

            Console.WriteLine($"{num1} - {num2} = {BigNum.Sub(num1, num2)}");
        }

        static void HeatMapTest()
        {
            //HeatMap.DrawDefaultMap();
            Random rand = new Random();
            List<PInfo> plist = new List<PInfo>();
            for (int i = 0; i < 50; i++)
            {
                plist.Add(new PInfo()
                {
                    X = rand.Next(-128, 128),
                    Y = rand.Next(0, 510),
                    N = rand.Next(0, 255)
                });
            }
            HeatMap.DrawPoints(plist);
        }
    }
}
